package br.ufpe.cin.rdfilter.gui;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Notes extends javax.swing.JFrame {


	public Notes(List<String> columnsName, List<String> feedback) {
		this.columnsName = columnsName;
		this.feedback = feedback;

		initComponents();
		setVisible(true);
	}

	public Notes(List<String> feedback){
		this.feedback = feedback;

		initComponents();
		setVisible(true);
	}

	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		notesTable = new javax.swing.JTable();

		setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);

		tableCreator();

		jScrollPane1.setViewportView(notesTable);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 693, Short.MAX_VALUE)
		);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
		);

		pack();
	}

	@SuppressWarnings("resource")
	private void tableCreator(){
		//CRIANDO TABELA
		//alterando para coluna fixa (por termo)
		/**String[] colunas = new String[columnsName.size()+2];

		for(int i = 0; i < columnsName.size(); i++){
			colunas[i] = columnsName.get(i);
		}
		colunas[columnsName.size()] = "Rating";
		colunas[columnsName.size()+1] = "Confidence Level";
		
		Scanner scan;
		Vector<String> dados = new Vector<String>();
		DefaultTableModel modelo = new DefaultTableModel(null, colunas);
		notesTable = new JTable( modelo );
		String linha;
		String[] row = new String[columnsName.size()+2];

		for(int a = 0; a < feedback.size(); a++){

			linha = feedback.get(a);

			scan = new Scanner(linha).useDelimiter("\\s*;\\s*");

			while(scan.hasNext()){
				dados.add(scan.next());
			}
			
			int x = 1;

			for(int i = 0; i < columnsName.size(); i++){

				row[i] = dados.get(x);
				x++;
			}
			row[columnsName.size()] = dados.get(x);
			x++;
			row[columnsName.size()+1] = dados.get(x);
			x++;
			modelo.addRow(row);
			dados.removeAllElements();

		}

		//FIM DE CRIANDO TABELA
	*/
		
		String[] colunas = new String[5];
		colunas[0]="Query";
		colunas[1]="User";
		colunas[2]="Term";
		colunas[3]="Rating";
		colunas[4]="Confidence";
		Scanner scan;
		List<String> dados = new ArrayList<String>();
		DefaultTableModel modelo = new DefaultTableModel(null, colunas);
		notesTable = new JTable( modelo );
		String linha;
		String[] row = new String[5];

		for(int a = 0; a < feedback.size(); a++){

			linha = feedback.get(a);

			scan = new Scanner(linha).useDelimiter("\\s*;\\s*");

			while(scan.hasNext()){
				dados.add(scan.next());
			}
			
//			int x = 1;

			for(int i = 0; i < 5; i++){

				row[i] = dados.get(i);
			}
			modelo.addRow(row);
			dados.removeAll(dados);

		}
	}

	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable notesTable;
	private List<String> columnsName;
	private List<String> feedback;

}
